﻿using System.Text;

namespace DotNetEncodingDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // 注册字符编码。
            //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            string myString = "你好呀！";
            System.Console.WriteLine("字符串：" + myString);
            System.Console.WriteLine();
            System.Console.WriteLine($"String Length: {myString.Length}");

            var ascii = Encoding.ASCII.GetBytes(myString);
            System.Console.WriteLine($"ASCII Length: {ascii.Length}");


            var utf32 = Encoding.UTF32.GetBytes(myString);
            System.Console.WriteLine($"UTF32 Length: {utf32.Length}");

            var utf7 = Encoding.UTF7.GetBytes(myString);
            System.Console.WriteLine($"UTF7 Length: {utf7.Length}");

            var utf8 = Encoding.UTF8.GetBytes(myString);
            System.Console.WriteLine($"UTF8 Length: {utf8.Length}");

            //var gb2312 = Encoding.GetEncoding("gb2312").GetBytes(myString);
            //System.Console.WriteLine($"GB2312 Length: {gb2312.Length}");

            //var gbk = Encoding.GetEncoding("gbk").GetBytes(myString);
            //System.Console.WriteLine($"GBK Length: {gbk.Length}");

            System.Console.WriteLine();

            var encodeInfos = Encoding.GetEncodings();
            System.Console.WriteLine($"编码类型数量：{encodeInfos.Length}");

            foreach (var encodeInfo in encodeInfos)
            {
                System.Console.WriteLine(encodeInfo.DisplayName);
            }
        }
    }
}
